package socket;

import java.net.*;
import java.util.Enumeration;

/**
 * @classname:Address
 * @description:
 * @author: Mr.Z
 * @date: 2020/12/21 17:10
 * @version: 0.1
 * @since:1.8
 */
public class Address {
    public static void main(String[] args) {
        try {
            Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
            while (interfaces.hasMoreElements()){
                NetworkInterface networkInterface = interfaces.nextElement();
                Enumeration<InetAddress> inetAddresses = networkInterface.getInetAddresses();
                while (inetAddresses.hasMoreElements()){
                    InetAddress inetAddress = inetAddresses.nextElement();
                    if(inetAddress instanceof Inet4Address){
                        System.out.println("ipv4:"+inetAddress);
                    }else
                        System.out.println("ipv6:"+inetAddress);

                }
            }
            System.out.println("----------------------");

        } catch (SocketException e) {
            e.printStackTrace();
        }

    }
}
